﻿using System;
using System.Xml.Serialization;

namespace WhiteFlow.DevTrackingTool.UI.Models
{
    [Serializable]
    public class TaskExecutionSummary : WorksheetItem
    {
        #region Constants

        public const string TitlePropertyName = "Title";

        public const string TotalTimePropertyName = "TotalTime";

        public const string TotalTimeDecimalPropertyName = "TotalTimeDecimal";

        public const string IsTrackedInWebSitePropertyName = "IsTrackedInWebSite";

        public const string IsTrackedInTfsPropertyName = "IsTrackedInTfs";

        #endregion

        #region Fields

        private string title;

        private TimeSpan totalTime;

        private double totalTimeDecimal;

        private ExtendedBoolean isTrackedInWebSite;
        
        private ExtendedBoolean isTrackedInTfs;

        #endregion

        #region Properties

        [XmlAttribute(AttributeName = TitlePropertyName)]
        public string Title
        {
            get { return title; }
            set
            {
                title = value;
                OnPropertyChanged(TitlePropertyName);
                OnWorksheetItemChanged();
            }
        }

        [XmlIgnore]
        public TimeSpan TotalTime
        {
            get { return totalTime; }
            set
            {
                totalTime = value;
                OnPropertyChanged(TotalTimePropertyName);
                OnWorksheetItemChanged();

                TotalTimeDecimal = totalTime.TotalHours;
            }
        }

        [XmlAttribute(AttributeName = TotalTimePropertyName)]
        public long TotalTimeTicks
        {
            get { return TotalTime.Ticks; }
            set { TotalTime = new TimeSpan(value); }
        }

        [XmlIgnore]
        public double TotalTimeDecimal
        {
            get { return totalTimeDecimal; }
            set
            {
                totalTimeDecimal = Math.Round(value, 2, MidpointRounding.AwayFromZero);
                OnPropertyChanged(TotalTimeDecimalPropertyName);
                OnWorksheetItemChanged();
            }
        }

        [XmlAttribute(AttributeName = IsTrackedInWebSitePropertyName)]
        public ExtendedBoolean IsTrackedInWebSite
        {
            get { return isTrackedInWebSite; }
            set
            {
                isTrackedInWebSite = value;
                OnPropertyChanged(IsTrackedInWebSitePropertyName);
                OnWorksheetItemChanged();
            }
        }

        [XmlAttribute(AttributeName = IsTrackedInTfsPropertyName)]
        public ExtendedBoolean IsTrackedInTfs
        {
            get { return isTrackedInTfs; }
            set
            {
                isTrackedInTfs = value;
                OnPropertyChanged(IsTrackedInTfsPropertyName);
                OnWorksheetItemChanged();
            }
        }

        #endregion
    }
}